#include<bits/stdc++.h>
#define ll long long
#define L x<<1
#define R x<<1|1
#define mid ((l+r)>>1)
#define lc L,l,mid
#define rc R,mid+1,r
#define Root 1,1,n
#define OK Ll<=l&&r<=Rr
#define rep(x,y,z) for(int x=(y);x<=(z);x++)
#define per(x,y,z) for(int x=(y);x>=(z);x--)
#define repn(x) rep(x,1,n)
#define repm(x) rep(x,1,m)
#define pb push_back
#define e(x) for(int i=h[x],y=to[i];i;i=nxt[i],y=to[i])
#define E(x) for(auto y:p[x])
#define Pi pair<int,int>
#define ui unsigned ll
#define YY puts("Yes"),exit(0)
#define NN puts("No"),exit(0)
#define yy return puts("Yes"),void()
#define nn return puts("No"),void()
inline int read(){int s=0,w=1;char c=getchar();while(c<48||c>57) {if(c=='-') w=-1;c=getchar();}while(c>=48&&c<=57)s=(s<<1)+(s<<3)+c-48,c=getchar();return s*w;}
inline void pf(int x){if(x<0) putchar('-'),x=-x;if(x>9)pf(x/10);putchar(x%10+48);}
using namespace std;
const int N=2e5+5,M=4e6+5,inf=(1LL<<30)-1,mod=998244353;
const ll llf=1e18;
inline void add(int &a,int b){((a+=b)>=mod) and (a-=mod);}
inline int Add(int a,int b){return add(a,b),a;}
inline int mul(int a,int b){return 1LL*a*b%mod;}
inline void Mul(int &a,int b){a=mul(a,b);}
inline void red(int &a,int b){add(a,mod-b);}
inline int Red(int a,int b){return red(a,b),a;}
inline int qp(int a,ll b){if(!b)return 1;int c=qp(a,b>>1LL);Mul(c,c);if(b&1)Mul(c,a);return c;}
inline int INV(int x){return qp(x,mod-2);}
inline bool che(int x,int p){return (x>>p)&1LL;}
int n,v[N],ans;
int c[N],a[N];
inline void subtaskA(){
	int Mx=0;
	per(i,n,1){
		Mx=max(Mx,v[i]);
		add(ans,mul(Mx,c[i]));
	}
	cout <<ans;
}
inline void subtaskB(){
	repn(i){
		if(!v[i]){
			if(c[i]>=a[i])c[i]-=a[i],c[i+1]++;
		}else {
			add(ans,mul(v[i],c[i]));
		}
	}
	cout <<ans;
}
inline void subtaskC(){
	rep(i,1,n-1){
		ll W=(ll)a[i]*v[i];
		if(W>v[i+1])continue;
		int T=c[i]/a[i];
		c[i+1]+=T,c[i]%=a[i];
	}
	repn(i)add(ans,mul(c[i],v[i]));
	cout <<ans;
}
ll dp[M],F[M],pr[M];
inline void subtask1(){
	int m=0;
	dp[0]=0;
	rep(i,0,N-5)F[i]=-llf;
	repn(l){
		int r=l,s=0,Mx=0;
		while(r<n&&a[r]==1)r++;
		per(i,r,l){
			Mx=max(Mx,v[i]);
			while(c[i]--)s++,pr[s]=pr[s-1]+Mx;
		}
		repm(i)pr[s+i]=pr[s+i-1]+Mx;
		if(r==n){
			ll ans=-llf;
			rep(i,0,m)ans=max(ans,dp[i]+pr[s+i]);
			cout <<ans%mod;
			return;
		}
		int nx=0;
		rep(ps,0,m){
			int ns=ps+s;
			nx=max(nx,ns/a[r]);
			rep(T,0,ns/a[r]){
				int k=T*a[r];
				F[T]=max(F[T],dp[ps]+pr[ns]-pr[k]);
			}
		}
		rep(i,0,nx)dp[i]=F[i],F[i]=-llf;
		m=nx;
		l=r;
	}
}
inline void Main(){
	n=read();
	bool sub1=n<=2000;
	repn(i)v[i]=read(),sub1&=v[i]<=2000;
	repn(i)c[i]=read(),sub1&=c[i]<=2000;
	bool subA=1,subB=1;
	rep(i,1,n-1)a[i]=read(),subA&=a[i]==1,subB&=a[i]==1000000000;
	if(subA)return subtaskA();
	if(subB)return subtaskB();
	if(sub1)return subtask1();
	return subtaskC();
}
signed main(){
	freopen("b.in","r",stdin);
	freopen("b.out","w",stdout);
	int T=1;
	while(T--)Main();
	return 0;
}
